
import { ref } from 'vue';
import { deletePaperPurchaseOrderApi } from '@/api/sj/purchaseManagement/paperProcurement/index';

const useEditPurchaseOrder = () => {

    const editVisible = ref(false);
    const revokeVisible = ref(false);

    const editObj = ref({});

    /**
     * @description: 打开采购编辑
     */
    const handleOpenEditClick = (row: any) => {
        console.log(row);
        editObj.value = row;
        editVisible.value = true;
    };


    /**
     * @description: 打开撤销
     */
    const handleOpenRevoke = (row: any) => {
        console.log(row);
        revokeVisible.value = true;
    };

    /**
     * @description: 删除采购单
     */
    const handleDelete = (row: any, fn: Function) => {
        // 材料已入库或已部分入库，无法刷除
        ElMessageBox.confirm('您确认把此条数据放入回收站么？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        })
            .then(async () => {
                try {
                    const { code } = await deletePaperPurchaseOrderApi(row.id);
                    if (code == 200) {
                        ElMessage({
                            type: 'success',
                            message: '删除成功!'
                        });

                        fn();
                    }
                } catch (error) {

                }

            })
            .catch(() => { });
    };


    return {
        editVisible,
        revokeVisible,
        editObj,
        handleOpenEditClick,
        handleOpenRevoke,
        handleDelete
    }
};

export default useEditPurchaseOrder;